﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using WLWeb.PulbicClass;

namespace WLWeb.Common
{
    public partial class News : System.Web.UI.Page
    {
        private int pageSizeNum = 20;
        /// <summary>
        /// 每页显示的条数
        /// </summary>
        public int PageSizeNum
        {
            get { return pageSizeNum; }
            set { pageSizeNum = value; }
        }
        string OtherCategoryID = "";
        BLL.wlBLL.Acticle act = new BLL.wlBLL.Acticle();
        protected void Page_Load(object sender, EventArgs e)
        {
            webleft1.Acticle = Webpublic.GetGroupName(2);
            webleft1.Title = "新闻动态";
            InitData();
        }
        protected void InitData()
        {
            Hashtable htWhere = new Hashtable();
            if (Request.QueryString["OtherCategoryID"] != null && Request.QueryString["OtherCategoryID"].ToString() != "")
            {
                OtherCategoryID = Request.QueryString["OtherCategoryID"].ToString();
            }
            if (OtherCategoryID == "")
            {
                htWhere.Add("OtherCategoryGroup", Webpublic.GetGroupName(2));                //组别为新闻的类型
            }
            else
            {
                htWhere.Add("OtherCategoryID", OtherCategoryID);        //分类ID

            }
            DataTable dtShow = act.GetActicleInfo(htWhere);
            if (dtShow != null && dtShow.Rows.Count > 0)
            {
                litHead.Text = dtShow.Rows[0]["OtherCategoryName"].ToString();
                litTitle.Text = "<a href=\"../Common/Index.aspx\">网站首页</a> &gt;&gt; <a href=\"../Common/News.aspx?OtherCategoryID=" + dtShow.Rows[0]["OtherCategoryID"].ToString() + "\">" + dtShow.Rows[0]["OtherCategoryName"].ToString() + "</a>";
                repDataShow.DataSource = dtShow;
                repDataShow.DataBind();

                PagedDataSource objPds = new PagedDataSource();
                objPds.DataSource = dtShow.DefaultView;
                objPds.AllowPaging = true;
                objPds.PageSize = pageSizeNum;
                int CurPage = 0;
                if (Request.QueryString["page"] != null && !string.IsNullOrEmpty(Request.QueryString["page"].ToString()))
                    CurPage = Convert.ToInt32(Request.QueryString["Page"].ToString());
                else
                    CurPage = 0;

                objPds.CurrentPageIndex = CurPage;

                if (dtShow != null && dtShow.Rows.Count > 0)
                {
                    repDataShow.DataSource = objPds;
                    repDataShow.DataBind();
                    pagesize1.PageCount = dtShow.Rows.Count / pageSizeNum;
                    pagesize1.PageSizeNum = pageSizeNum;
                    pagesize1.PageIndex = CurPage;
                    pagesize1.DataCount = dtShow.Rows.Count;
                    pagesize1.PageUrl = "../Common/News.aspx?ExampleCategoryId=" + OtherCategoryID + "&";
                    pagesize1.ControlInit();

                }
                else
                {
                    pagesize1.Visible = false;
                }
            }
            else
            {
                pagesize1.Visible = false;
            }

        }
        protected string IsAddnew(string datetime)
        {
            if (datetime != null && datetime != "")
            {
                if (Convert.ToDateTime(datetime).AddDays(1) >= DateTime.Now)
                {
                    return "<font style=\"font-family: Arial; color: rgb(255, 0, 0);\">&nbsp;&nbsp;new</font>";
                }
            }
            return "<font style=\"font-family: Arial; color: rgb(255, 0, 0);\"></font>";
        }
    }
}